﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Collections
{
    public static class IEnumerableEx
    {
        public static void Foreach(this System.Collections.IEnumerable collection, Action<Object> func)
        {
            foreach (Object element in collection)
            {
                func(element);
            }
        }

        public static void Foreach<TElement>(this IEnumerable<TElement> collection, Action<TElement> func)
        {
            foreach (TElement element in collection)
            {
                func(element);
            }
        }

        public static Boolean IsSubsetOf<TElement>(this IEnumerable<TElement> sub, IEnumerable<TElement> super)
        {
            return sub.All(elem => super.Contains(elem));
        }

        public static Boolean IsSupersetOf<TElement>(this IEnumerable<TElement> super, IEnumerable<TElement> sub)
        {
            return sub.IsSubsetOf(super);
        }
    }
}
